<!--
 * @Description: 我的订单页面组件
 * @Author: pdx
 * @Date: 2021-11-20 17:21:54
 * @LastEditors: pdx
 * @LastEditTime: 2021-11-27 13:36:27
 -->
<template>
  <div class="order">
    <!-- 我的订单头部 -->
    <div class="order-header">
      <div class="order-header-content">
        <p>
          <i class="el-icon-s-order" style="font-size: 30px;color: #ff6700;"></i>
          我的订单
        </p>
      </div>
    </div>
    <!-- 我的订单头部END -->

    <!-- 分类标签 -->
    <div class="nav">
      <div class="product-nav">
        <div class="title">分类</div>
        <el-tabs v-model="activeStatus" type="card" @tab-click="getOrderListByTab">
          <el-tab-pane
              v-for="item in statusList"
              :key="item.status"
              :label="item.name"
              :name="''+item.status"
          />
        </el-tabs>
      </div>
    </div>

    <!-- 我的订单主要内容 -->
    <div class="order-content" v-if="orders.length > 0">
      <div class="content" v-for="(item,index) in orders" :key="index">
        <ul>
          <!-- 我的订单表头 -->
          <li class="order-info">
            <div class="order-id">订单编号: {{item.orderSn}}</div>
            <div class="order-time">订单时间: {{item.createTime}}</div>
          </li>
          <li class="header">
            <div class="pro-img"></div>
            <div class="pro-name">商品名称</div>
            <div class="pro-price">单价</div>
            <div class="pro-num">数量</div>
            <div class="pro-total">小计</div>
          </li>
          <!-- 我的订单表头END -->

          <!-- 订单列表 -->
          <li class="product-list" v-for="(game,i) in item.orderItems" :key="i">
            <div class="pro-img">
              <router-link :to="{ path: '/game/details', query: {id : game.gameId} }" target="_blank">
                <img style="width : 130px; height: 85px; border-radius: 10px" :src="game.gameDefImg" />
              </router-link>
            </div>
            <div class="pro-name">
              <router-link :to="{ path: '/game/details', query: {id : game.gameId} }" target="_blank">
                {{game.gameName}}</router-link>
            </div>
            <div class="pro-price">{{game.realAmount}} 元</div>
            <div class="pro-num">{{game.gameQuantity}}</div>
            <div class="pro-total pro-total-in">{{game.realAmount * game.gameQuantity}} 元</div>
          </li>
        </ul>
        <div class="order-bar">
          <div class="order-bar-left">
            <span class="order-total">
              共
              <span class="order-total-num">{{item.orderItems.length}}</span> 件商品
            </span>
          </div>

          <div class="order-bar-right-button">
            <el-button type="danger" v-if="item.status == 0" @click="toPayOrder(item.orderSn)">立即支付</el-button>
            <el-button type="info" v-if="item.status == 0" @click="cancelOrder(item.orderSn)">取消订单</el-button>
            <el-button type="danger" v-if="item.status == 2" @click="confirmReceipt(item.orderSn)">确认收货</el-button>
            <div class="order-bar-right-span">
              <span v-if="item.status == 1">待发货</span>
              <span v-if="item.status == 3">已完成</span>
              <span v-if="item.status == 4">已关闭</span>
              <span v-if="item.status == 5">无效订单</span>
            </div>
          </div>

          <div class="order-bar-right">
            <span>
              <span class="total-price-title">合计：</span>
              <span class="total-price">{{item.price}} 元</span>
            </span>
          </div>
          <!-- 订单列表END -->
        </div>
      </div>
      <div style="margin-top:-40px;"></div>
    </div>
    <!-- 我的订单主要内容END -->

    <!-- 订单为空的时候显示的内容 -->
    <div v-else class="order-empty">
      <div class="empty">
        <h2>您的订单还是空的！</h2>
        <p>快去购物吧！</p>
      </div>
    </div>
    <!-- 订单为空的时候显示的内容END -->
  </div>
</template>
<script>
import order from "@/api/order/order";

export default {
  data() {
    return {
      orders: [], // 订单列表
      total: [], // 每个订单的商品数量及总价列表
      statusList: [
        {
          status: -1,
          name: '全部'
        },
        {
          status: 0,
          name: '未支付'
        },
        {
          status: 3,
          name: '已完成'
        }
      ],
      activeStatus: '-1',
    };
  },
  activated() {
    // 获取订单数据
    this.getOrderList()
  },

  methods: {
    getOrderListByTab() {
      this.getOrderList()
    },

    getOrderList() {
      const param = {
        status: this.activeStatus < 0 ? '' : this.activeStatus
      }
      order.getOrderListInfo(param)
      .then(result => {
        const data = result.data
        if (data != null) {
          this.orders = data
        }else {
          this.orders = []
        }
      })
    },

    toPayOrder(orderSn) {
      this.$router.push({path: '/payOrder', query: {orderSn : orderSn}})
    },

    //确认收货
    confirmReceipt(orderSn) {

    },

    //取消订单
    cancelOrder(orderSn) {
      let status = 4;  //取消订单
      order.cancelOrderInfo(orderSn, status)
      .then(result => {
        this.getOrderList()
      })
    }
  }
};
</script>
<style scoped>
.order {
  background-color: #f5f5f5;
  padding-bottom: 20px;
}
/* 我的订单头部CSS */
.order .order-header {
  height: 64px;
  border-bottom: 2px solid #ff6700;
  background-color: #fff;
  margin-bottom: 20px;
}
.order .order-header .order-header-content {
  width: 1225px;
  margin: 0 auto;
}
.order .order-header p {
  font-size: 28px;
  line-height: 58px;
  float: left;
  font-weight: normal;
  color: #424242;
}
/* 我的订单头部CSS END */
.order .content {
  width: 1225px;
  margin: 0 auto;
  background-color: #fff;
  margin-bottom: 50px;
}

.order .content ul {
  background-color: #fff;
  color: #424242;
  line-height: 85px;
}
/* 我的订单表头CSS */
.order .content ul .order-info {
  height: 60px;
  line-height: 60px;
  padding: 0 26px;
  color: #424242;
  border-bottom: 1px solid #ff6700;
}
.order .content ul .order-info .order-id {
  float: left;
  color: #ff6700;
}
.order .content ul .order-info .order-time {
  float: right;
}

.order .content ul .header {
  height: 85px;
  padding-right: 26px;
  color: #424242;
}
/* 我的订单表头CSS END */

/* 订单列表CSS */
.order .content ul .product-list {
  height: 85px;
  padding: 15px 26px 15px 0;
  border-top: 1px solid #e0e0e0;
}
.order .content ul .pro-img {
  float: left;
  height: 85px;
  width: 120px;
  padding-left: 80px;
}
.order .content ul .pro-img img {
  height: 80px;
  width: 150px;
}
.order .content ul .pro-name {
  margin-left: 20px;
  float: left;
  width: 300px;
}
.order .content ul .pro-name a {
  color: #424242;
}
.order .content ul .pro-name a:hover {
  color: #ff6700;
}
.order .content ul .pro-price {
  float: left;
  width: 160px;
  padding-right: 18px;
  text-align: center;
}
.order .content ul .pro-num {
  float: left;
  width: 190px;
  text-align: center;
}
.order .content ul .pro-total {
  float: left;
  width: 160px;
  padding-right: 81px;
  text-align: right;
}
.order .content ul .pro-total-in {
  color: #ff6700;
}

.order .order-bar {
  width: 1185px;
  padding: 0 20px;
  border-top: 1px solid #ff6700;
  height: 50px;
  line-height: 50px;
  background-color: #fff;
}
.order .order-bar .order-bar-left {
  float: left;
}
.order .order-bar .order-bar-left .order-total {
  color: #757575;
}
.order .order-bar .order-bar-left .order-total-num {
  color: #ff6700;
}
.order .order-bar .order-bar-right {
  float: right;
}
.order .order-bar .order-bar-right .total-price-title {
  color: #ff6700;
  font-size: 14px;
}
.order .order-bar .order-bar-right .total-price {
  color: #ff6700;
  font-size: 30px;
}

.order .order-bar .order-bar-right-button {
  margin-left: 10px;
  float: right;
}

.order-bar-right-span {
  color: #000000;
  font-size: 20px;
}
/* 订单列表CSS END */

/* 订单为空的时候显示的内容CSS */
.order .order-empty {
  width: 1225px;
  margin: 0 auto;
}
.order .order-empty .empty {
  height: 300px;
  padding: 0 0 130px 558px;
  margin: 65px 0 0;
  background: url(../assets/imgs/cart-empty.png) no-repeat 124px 0;
  color: #b0b0b0;
  overflow: hidden;
}
.order .order-empty .empty h2 {
  margin: 70px 0 15px;
  font-size: 36px;
}
.order .order-empty .empty p {
  margin: 0 0 20px;
  font-size: 20px;
}
/* 订单为空的时候显示的内容CSS END */

.nav {
  background-color: white;
}

.nav .product-nav {
  width: 1225px;
  height: 40px;
  line-height: 40px;
  margin: 0 auto;
}

.nav .product-nav .title {
  width: 50px;
  font-size: 16px;
  font-weight: 700;
  float: left;
}

.order-content {
  margin-top: 10px;
}
</style>